#include "storeview.h"
#include "ui_storeview.h"

StoreView::StoreView(QWidget *parent,int sid) :
    QMainWindow(parent),
    ui(new Ui::StoreView)
{
    ui->setupUi(this);
    m_sid = sid;
    myDatabase.getConnection();


}

StoreView::~StoreView()
{
    delete ui;
}

void StoreView::on_Store_info_clicked()
{
    StoreInfo* psinfo = new StoreInfo(this,m_sid);
    qDebug()<<"view sid = "<<m_sid;
    psinfo->show();
}


void StoreView::on_Quit_clicked()
{
    this->~StoreView();
    MainWindow* pmwd = new MainWindow();
    pmwd->show();
}


void StoreView::on_Import_goods_clicked()
{
    ImportGoods* pig = new ImportGoods(this,this->m_sid);
    pig->show();
}



void StoreView::on_Check_clicked()
{

    static QSqlQueryModel *mode= new QSqlQueryModel(ui->tableView);
    mode->setQuery("SELECT gcat,name,price,num,info FROM tb_goodsinstore NATURAL JOIN tb_goods WHERE sid = "+QString::number(m_sid)+" ORDER BY gcat");

    mode->setHeaderData(0,Qt::Horizontal,tr("cat"));
    mode->setHeaderData(1, Qt::Horizontal, tr("name"));
    mode->setHeaderData(2, Qt::Horizontal, tr("price"));
    mode->setHeaderData(3, Qt::Horizontal, tr("num"));
    mode->setHeaderData(4, Qt::Horizontal, tr("info"));


    ui->tableView->setModel(mode);
}


void StoreView::on_Add_goods_clicked()
{
    Addgoods* pag = new Addgoods(nullptr,m_sid);
    pag->show();
}


void StoreView::on_Export_goods_clicked()
{
    Exportgoods* peg = new Exportgoods(this,m_sid);
    peg->show();
}


void StoreView::on_Modify_goods_clicked()
{
    Modifygoods* pmg = new Modifygoods(this,m_sid);
    pmg->show();
}

